import './AdDisablePatch'; // 广告禁用补丁 - 必须在最前面
import { _decorator, Component, Node, ProgressBar } from 'cc';
import { AdComponent } from './AdComponent';
import *as cc from "cc";
import GlobeData from './GlobeData';
import { MainWork } from './MainWork';
import DatasSpace from './Tool/DatasSpace';
import { MISSION_TYPE } from '../Cube/Levels';
import { AudioMgr } from './Tool/AudioMgr';
import SkdComm from './SkdComm';
const { ccclass, property } = _decorator;

@ccclass('Loading')
export class Loading extends MainWork {

  @property({ type: ProgressBar })
  loadingProbar: ProgressBar = null;

  start() {
    this.startLoadingRun();
    SkdComm.Instance.initShare();
    DatasSpace.Instance.initData();
    DatasSpace.Instance.setInt('DailyMission_' + MISSION_TYPE.SIGN, 1);
    AudioMgr.Instance.init();
  }

  startLoadingRun() {
    console.log('初始化广告系统');
    AdComponent.Instance.createAds(); // 重新启用广告创建（现在支持快手广告）
    this.preloadScene('Home');
    GlobeData.Instance.loadingInitData();
    this.loadProgress();
  }

  preloadScene(sceneName: string) {
    cc.director.preloadScene(sceneName);
  }

  loadProgress() {
    cc.tween(this.loadingProbar).to(2, { progress: 1 }).call(() => {
      cc.director.loadScene('Home');
    }).start();
  }

  // update(deltaTime: number) {

  // }
}


